<?php
/*
 * 信息搜索页面调用的车型搜索信息
 * @package    logical
 * @author     Mark
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 72fdc1348e201df0cc7ce10f33d31eb20d93600a $
 */

$CTPS               = AutoCategoryLevel::relatives($filter['ctp'], true);
$autoLevelParentids = AutoCategoryLevel::parentids($filter['ctp'], true);

$filter = isset($filter) ? $filter : array();
// 补全变量
if ($filter['mid']) {
	$MODEL = AutoModel::get($filter['mid']);
	$filter['bid']   = $MODEL['arbid'];
	$filter['cid']   = $MODEL['arcid'];
}

if ($filter['cid']) {
	if (!$filter['bid']) {
		$brand = AutoCar::get($cid);
		$filter['bid']   = $brand['arid'];
	}
}

$autoFilter = array();
if ($filter['cid']) $autoFilter['arcid'] = $filter['cid'];
if ($filter['ctp']) $autoFilter['acid'] = $filter['ctp'];
if ($filter['cen']) $autoFilter['engine'] = AutoCategory::TYPE_RANK_NEWENERGY;
if ($filter['bid']) $autoFilter['arbid'] = $filter['bid'];


if ($autoFilter) {
	$carids = AutoModel::getDistinctList($autoFilter, 'arcid');
	$brandids = AutoModel::getDistinctList($autoFilter, 'arbid');

	$CARS = AutoCar::getShort($carids);
	$BRANDS = AutoBrand::getFull($brandids);
	$LBRANDS = AutoBrand::sortByLetter($BRANDS);
	$WORDS   = array_keys($LBRANDS);

	if($autoFilter['arbid']) {
		$FILTER_CARS = AutoCar::getList($autoFilter);
	}
	if ($autoFilter['arcid']) {
		$FILTER_MODELS = AutoModel::getList($autoFilter);
	}
}